const { ipcRenderer } = require("electron");
const { port1, port2 } = new MessageChannel();

/**
 * channel 通道名 port
 * null 传递给主进程的消息
 * portArr 端口数组
 */
ipcRenderer.postMessage("port", null, [port2]);

document.getElementById("sendMessage").addEventListener("click", () => {
  // 创建MessageChannel，然后将Port2传递给主进程
  port1.postMessage("渲染进程传递的数据给主进程");
});
port1.onmessage = (event) => {
  console.log(event.data);
};
